package top.spring.study.dto;

import java.io.Serializable;

public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    private boolean succ;
    private String excId;
    private int errCode;
    private String errType = "";
    private String errMsg;
    private T data;
    private Throwable exception;

    public Result() {
    }

    public void setErrType(String errType) {
        this.errType = errType;
    }

    public String getErrType() {
        return this.errType;
    }

    public boolean isSucc() {
        return this.succ;
    }

    public void setSucc(boolean succ) {
        this.succ = succ;
    }

    public int getErrCode() {
        return this.errCode;
    }

    public void setErrCode(int errCode) {
        this.errCode = errCode;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getErrMsg() {
        return this.errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public String getExcId() {
        return this.excId;
    }

    public void setExcId(String excId) {
        this.excId = excId;
    }

    public Throwable getException() {
        return this.exception;
    }

    public void setException(Throwable exception) {
        this.exception = exception;
    }

    public static <M> Result<M> ok(M data) {
        Result<M> Result = new Result();
        Result.setData(data);
        Result.setSucc(true);
        return Result;
    }

    public static <M> Result<M> warn(int errCode, String errMsg) {
        Result<M> Result = new Result();
        Result.setErrCode(errCode);
        Result.setErrType("W");
        Result.setErrMsg(errMsg);
        return Result;
    }

    public static <M> Result<M> error(int errCode, String errMsg) {
        Result<M> Result = new Result();
        Result.setErrCode(errCode);
        Result.setErrType("E");
        Result.setErrMsg(errMsg);
        return Result;
    }

    public static <M> Result<M> error(int errCode, String errMsg, Throwable exception) {
        Result<M> Result = error(errCode, errMsg);
        Result.setException(exception);
        return Result;
    }
}
